package com.taoism.utils;

import com.taoism.customEnum.MatchTypeEnum;

/**
 * 规则工具
 *
 * @author 李嘉
 * @version 1.0
 * @Description 规则工具
 * @date 2019-07-14 22:26
 */
public class MatcheUtil {

    /**
     * xls规则
     */
    private final static String xls = "^.+\\.(?i)(xls)$";

    /**
     * xlsx规则
     */
    private final static String xlsx = "^.+\\.(?i)(xlsx)$";

    /**
     * doc规则
     */
    private final static String doc = "^.+\\.(?i)(doc)$";

    /**
     * docx规则
     */
    private final static String docx = "^.+\\.(?i)(docx)$";

    /**
     * txt规则
     */
    private final static String txt = "^.+\\.(?i)(txt)$";

    /**
     * 规则的校验
     *
     * @param fileName      文件名称(包含后缀名)
     * @param matchTypeEnum 规则枚举， Excel，Word，Txt
     * @return
     */
    public static boolean matchExcel(String fileName, MatchTypeEnum matchTypeEnum) {
        boolean flag = false;
        switch (matchTypeEnum) {
            case EXCEL:
                flag = !fileName.matches(xls) && !fileName.matches(xlsx);
                break;
            case WORD:
                flag = !fileName.matches(doc) && !fileName.matches(docx);
                break;
            case TXT:
                flag = !fileName.matches(txt);
                break;
            default:
                break;
        }
        return flag;
    }
}
